package com.space.school.service.impl;

import com.space.school.dao.ProductListDao;
import com.space.school.dao.impl.ProductListDaoImpl;
import com.space.school.domain.ProductCategory;
import com.space.school.domain.User;
import com.space.school.service.productListService;
import com.space.school.utils.PageBean;

import java.util.List;
import java.util.Map;

public class ProductListServiceImpl implements productListService {
    private ProductListDao productListDao=new ProductListDaoImpl();

    @Override
    public PageBean<ProductCategory> search(Map<String, String[]> map, int currentPage, int pageSize) {
        int start = (currentPage - 1) * pageSize;
        List<ProductCategory> list=productListDao.search(map,start,pageSize);
        PageBean<ProductCategory> pb=new PageBean<>();
        pb.setList(list);
//        总数据数
        int count=productListDao.count(map);
        pb.setTotalCount(count);
//       每页显示数据数
        pb.setRows(pageSize);
//        当前页数
        pb.setCurrentPage(currentPage);
//        总页数
        int totalPage=(int) Math.ceil((double) count/pageSize);
        pb.setTotalPage(totalPage);
        return pb;
    }

    @Override
    public void del(int category_id) {
        productListDao.del(category_id);
    }

    @Override
    public ProductCategory find(int category_id) {
        return productListDao.find(category_id).get(0);

    }

    @Override
    public void update(ProductCategory productCategory) {
        productListDao.update(productCategory);
    }

    @Override
    public  List<ProductCategory> findAll() {
        return productListDao.findAll();
    }

}
